/**
 * 
 */

/**
 * @author Ashley
 *
 */
public class NotOp extends UnaryOp {

	/**
	 * @param newOp
	 */
	public NotOp() {
		super("!");
	}
	
	@Override
	public boolean isNotOp() { 
		return true; 
	}

	@Override
	// overrides the parent UnaryOp unaryOperand method to do the right check for notOp
	public STO unaryOperand(STO op) { 
		if (op.isError()) { 
			return op ;
		}
		STO sto = null;
		Type op_type = op.getType();
		if (op_type.isBool()){
			if(op.isConst()) {
				sto = new ConstSTO(op.getName(), new BoolType());
			}
			else {
				sto = new ExprSTO(op.getName(), new BoolType());
			}
		}
		else {
		 	sto = new ErrorSTO("error1u_Expr");
		}
		return sto; 
	}
	@Override
	public STO calculate(ConstSTO op) {
		ConstSTO sto;
		boolean b = !op.getBoolValue();
		String s;
		if(b == true) {
			s = "1";
		} else {
			s = "0";
		}
		sto = new ConstSTO("!" + op.getName() , new BoolType(), s);
		return sto;
	}
}
